package a26_Collection.TreeSet;

/**
 * @Author quan
 * @Description 对学生对象排序
 * @Date 2023/2/20 19:48
 */
//注意：这里要实现Comparable接口，而且类型已经确定，Comparable后面要写Student类
public class Student2 implements Comparable<Student2> {
   private String name;
   private int age;
   private int Chinese;
   private int math;
   private int english;

    public Student2() {
    }

    public Student2(String name, int age, int chinese, int math, int english) {
        this.name = name;
        this.age = age;
        Chinese = chinese;
        this.math = math;
        this.english = english;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getChinese() {
        return Chinese;
    }

    public void setChinese(int chinese) {
        Chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    @Override
    public String toString() {
        return "Student2{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", Chinese=" + Chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    //重写比较规则的方法
    @Override
    public int compareTo(Student2 o) {
        //指定比较规则
        int sum1 = this.getChinese()+this.getMath()+this.getEnglish();
        int sum2 = o.getChinese()+o.getMath()+o.getEnglish();
        int i = sum1-sum2;
        //比较两者的总分
        if(sum1==sum2){
            i = this.getChinese()-o.getChinese();
            //比较数学
            if(this.getChinese()==o.getChinese()){
                i = this.getMath()-o.getMath();
                //比较英语
            }if(this.getMath()==o.getMath()){
                i = this.getEnglish()-o.getEnglish();
                //比较年龄
            }if(this.getEnglish()==o.getEnglish()){
                i = this.getAge()-o.getAge();
                //比较姓名
            }if(this.getAge()==o.getAge()) {
                i = this.getName().compareTo(o.getName());//字符串使用默认的CompareTo方法进行排序
            }
        }else{
            i = sum1-sum2;
        }
            return i;

    }
}
